﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
using System.Text;
public partial class Quanlyuser : System.Web.UI.Page
{
    public void hienthi()
    {
        //string conn = "Server=MYSQL5002.myWindowsHosting.com;Database=db_9ab19d_dulieu;Port=3306;UserID=9ab19d_dulieu;Password=hoang123;charset=utf8";
        //MySqlConnection con = new MySqlConnection(conn);
        //MySqlDataAdapter ad = new MySqlDataAdapter("select * from tbl_users", con);
        //DataSet ds = new DataSet();
        //ad.Fill(ds, "tbl");
        //GridView1.DataSource = ds.Tables["tbl"];
        //GridView1.DataBind();


    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Variables.loginFlag)
        {
            Response.Redirect("Default.aspx");
            return;
        }
        hienthi();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
       GridView1.EditIndex = e.NewEditIndex;
       hienthi();
        
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //string conn = "Server=MYSQL5002.myWindowsHosting.com;Database=db_9ab19d_dulieu;Port=3306;UserID=9ab19d_dulieu;Password=hoang123;charset=utf8";
        //MySqlConnection con = new MySqlConnection(conn);
      
        //string key = "";
 
      
        //key = GridView1.Rows[e.RowIndex].Cells[1].Text;
        //Button1.Text = key;
        //MySqlCommand cmd = new MySqlCommand("delete from tbl_users where Username='" + key + "'", con);
        //con.Open();
        //cmd.ExecuteNonQuery();
        //GridView1.EditIndex = -1;
        //con.Close();
        //hienthi();
       

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
      
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        hienthi();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //string key = "";


        //key = (GridView1.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox).Text;

        ////TextBox pas = (TextBox)GridView1.Rows[e.RowIndex].FindControl("pas");
        //string Pass = (GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text;
        //string Role = (GridView1.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox).Text;
        //string email = (GridView1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text;
        //string conn = "Server=MYSQL5002.myWindowsHosting.com;Database=db_9ab19d_dulieu;Port=3306;UserID=9ab19d_dulieu;Password=hoang123;charset=utf8";
        //Button1.Text = Pass.ToString();
        
        //MySqlConnection con = new MySqlConnection(conn);
        //MySqlCommand cm = new MySqlCommand("Update tbl_users set Password='" + Pass + "', Role='" + Role + "',Email='" + email + "' where Username='admin'", con);
        //MySqlCommand cm = new MySqlCommand("update tbl_users set Password='abc',Role='abc',Email='"+ email +"' where Username='"+ key +"'", con);
        //con.Open();
        //cm.ExecuteNonQuery();
        //GridView1.EditIndex = -1;
        //con.Close();
        //hienthi();
       
       
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }
    protected void GridView1_Load(object sender, EventArgs e)
    {
       
    }
}